function setActiveStyleSheetCursor(title) {
if(window.event.keyCode == 13) {
setActiveStyleSheet(title)
}
}
function setActiveStyleSheet(title) {
var i, a, main;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
a.disabled = true;
if(a.getAttribute("title") == title) a.disabled = false;
}
}
}
function getActiveStyleSheet() {
var i, a;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
}
return null;
}
function getPreferredStyleSheet() {
var i, a;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1
&& a.getAttribute("rel").indexOf("alt") == -1
&& a.getAttribute("title")
) return a.getAttribute("title");
}
return null;
}

function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
window.onload = function(e) {
var cookie = readCookie("style");
if ((cookie == "s1") || (cookie == "s2") || (cookie == "s3"))  {
cookie="";
}
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
}
window.onunload = function(e) {
var title = getActiveStyleSheet();
createCookie("style", title, 365);
}
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

//*** OTRAS FUNCIONES ***
function fecha() {
                var d=new Date()
                var weekday=new Array(7)
                weekday[0]="Domingo"
                weekday[1]="Lunes"
                weekday[2]="Martes"
                weekday[3]="Miercoles"
                weekday[4]="Jueves"
                weekday[5]="Viernes"
                weekday[6]="Sabado"

                var mes=new Array(12)
                mes[0]="enero"
                mes[1]="febrero"
                mes[2]="marzo"
                mes[3]="abril"
                mes[4]="mayo"
                mes[5]="junio"
                mes[6]="julio"
                mes[7]="agosto"
                mes[8]="septiembre"
                mes[9]="octubre"
                mes[10]="noviembre"
                mes[11]="diciembre"

                document.write("<B>");
                document.write( weekday[d.getDay()] );
                document.write(String.fromCharCode(60)+"/B"+String.fromCharCode(62));
                document.write(", " + d.getDate() + "  de " + mes[d.getMonth()] + " de " + d.getFullYear());
}


function titulo() {
                                var titulo_txt="";
                                if (location.href.lastIndexOf("?tp=") > 0 )
                                   titulo_txt = location.href.substring(location.href.lastIndexOf("?tp=")+4,location.href.length);
                                if (location.href.lastIndexOf("&tp=") > 0 )
                                   titulo_txt = location.href.substring(location.href.lastIndexOf("&tp=")+4,location.href.length);
                                if (titulo_txt.lastIndexOf("&") > 0 )
                                   titulo_txt = titulo_txt.substring(0,titulo_txt.lastIndexOf("&"));

                                var posicion=titulo_txt.lastIndexOf("%");
                                while (posicion > 1)
                                {
                                   titulo_txt=titulo_txt.replace(titulo_txt.substring(posicion,posicion+3),String.fromCharCode(parseInt(titulo_txt.substring(posicion+1,posicion+3),16)) );
                                   posicion=titulo_txt.lastIndexOf("%");
                                }
                                document.write( titulo_txt );
}

